package cc.kzc.adminauth.misc;

public class NumericUtil {

	public static int compare(Integer i1, Integer i2) {
		return Integer.compare(intValue(i1), intValue(i2));
	}

	public static boolean equals(int i, Integer jObj) {
		if (null == jObj) {
			return false;
		}
		int j = jObj.intValue();
		return i == j;
	}

	public static boolean equals(Integer iObj, int j) {
		return equals(j, iObj);
	}

	public static int intValue(Number obj) {
		if (null == obj) {
			return 0;
		}
		return obj.intValue();
	}
	
	public static long longValue(Number obj) {
		if (null == obj) {
			return 0L;
		}
		return obj.longValue();
	}

	public static boolean isEmpty(final CharSequence cs) {
		return cs == null || cs.length() == 0;
	}

	public static boolean isNumeric(final CharSequence cs) {
		if (isEmpty(cs)) {
			return false;
		}
		final int sz = cs.length();
		for (int i = 0; i < sz; i++) {
			if (!Character.isDigit(cs.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	public static long parseLong(String str) {
		if (!isNumeric(str)) {
			return -1L;
		}
		return Long.parseLong(str);
	}

	public static String toStringNotNull(Number obj) {
		if (null == obj) {
			return "";
		}
		return obj.toString();
	}
}
